package com.agy.filemanager.controller;

import com.agy.filemanager.common.PageUtil;
import com.agy.filemanager.entity.ProExpandInfo;
import com.agy.filemanager.entity.ProType;
import com.agy.filemanager.service.ProExpandInfoService;
import com.agy.filemanager.service.ProTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.GET;
import java.util.List;

/**
 * 项目分类Controller
 */
@RestController
@RequestMapping("pro/type")
public class ProTypeController {

    @Autowired
    private ProTypeService proTypeService;

    @Autowired
    private ProExpandInfoService proExpandInfoService;

    /**
     * 根据项目大分类查询 项目分类
     * @param page
     * @param rows
     * @param mainTypeId
     * @return
     */
    @GetMapping("page")
    public ResponseEntity<PageUtil> getProTypePageByMainType(int page ,int rows , @RequestParam(value = "id",required = true) String mainTypeId){
        PageUtil<ProType> pageContent = proTypeService.getProTypeByMainTypeId(page, rows, mainTypeId);
        return  ResponseEntity.ok(pageContent);
    }

    /**
     *  保存项目分类的基础数据
     * @param proType
     * @return 项目分类id
     */
    @PostMapping("entity")
    public ResponseEntity<String> insertProTypeBasicData(ProType proType){
        String id  = proTypeService.insertProTypeBasicData(proType);
        return  ResponseEntity.ok(id);
    }

    /**
     *  修改项目分类基础数据
     * @param proType
     * @return
     */
    @PutMapping("entity")
    public ResponseEntity<String> updateProTypeBasicData(ProType proType){
        proTypeService.updateProTypeBasicData(proType);
        return  ResponseEntity.ok("修改成功！");
    }

    /**
     * 根据项目分类id为删除
     * @return
     */
    @DeleteMapping("entity")
    public ResponseEntity<String> deleteProTypeBasicData(ProType proType){
        proTypeService.deleteProTypeBasicData(proType);
        return  ResponseEntity.ok("删除成功！");
    }

    /**
     * 项目分类列表
     * @return
     */
    @GetMapping("list")
    public ResponseEntity getProTypeList(@RequestParam("id") String mainTypeId,String name){
        PageUtil<ProType> proTypes = proTypeService.getProTypeList(mainTypeId,name);
        return  ResponseEntity.ok(proTypes);
    }

    /**
     * 根据项目类型插入扩展字段id
     * @return
     */
    @PostMapping("expand/entity")
    public ResponseEntity<String> insertProTypeExpandCloumnByTypeId(ProExpandInfo info){
        String id = proExpandInfoService.insertProTypeExpandCloumnByTypeId(info);
        return ResponseEntity.ok(id);
    }

    /**
     * 根据id删除扩展字段
     * @param id
     * @return
     */
    @DeleteMapping("expand/entity")
    public ResponseEntity<String> deleteProTypeExpandById(String id){
        proExpandInfoService.deleteProTypeExpandById(id);
        return  ResponseEntity.ok("保存成功！");
    }

    /**
     * 根据id修改扩展字段信息
     * @param info
     * @return
     */
    @PutMapping("expand/entity")
    public ResponseEntity<String> updateProTypeExpandById(ProExpandInfo info){
        proExpandInfoService.updateProTypeExpandById(info);
        return ResponseEntity.ok("修改成功！");
    }

}
